package homework;

import java.util.Arrays;
import java.util.Comparator;

/**
 * 比较
 */
//class Student implements Comparable<Student>{
//    private int age;
//    private String name;
//
//    public Student(int age, String name) {
//        this.age = age;
//        this.name = name;
//    }
//
//    @Override
//    public int compareTo(Student o) {
//        return this.age-o.age;
//    }
//
//
//    @Override
//    public String toString() {
//        return "Student{" +
//                "age=" + age +
//                ", name='" + name + '\'' +
//                '}';
//    }
//}
class Student {
    public int age;
    public String name;

    public Student(int age, String name) {
        this.age = age;
        this.name = name;
    }
    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                ", name='" + name + '\'' +
                '}';
    }
}
class ageCompare implements Comparator<Student>{

    @Override
    public int compare(Student o1, Student o2) {
        return o1.age-o2.age;
    }
}
class nameCompare implements Comparator<Student>{

    @Override
    public int compare(Student o1, Student o2) {
        return o1.name.compareTo(o2.name);
    }
}
public class HomeWork8 {
    public static void main(String[] args) {
        Student student1=new Student(20,"wsw");
        Student student2=new Student(17,"dsa");
        Student student3=new Student(23,"hfe");
        Student[]arr={new Student(20,"wsw"),
                new Student(17,"dsa"),
                new Student(23,"hfe")  };
        Arrays.sort(arr,new  nameCompare());
        System.out.println(Arrays.toString(arr));
    }
}
